#!/bin/sh

. /usr/share/common

config_file=/etc/webui/zerotier.conf
[ -f "$config_file" ] && . $config_file

case "$1" in
	start)
		if [ "false" = "$zerotier_enabled" ]; then
			echo_error "Zerotier-One service is disabled in $config_file"
			exit 1
		fi

		echo_title "Starting Zerotier-One"

		modprobe tun

		zerotier-one -d
		;;
	stop)
		echo_title "Stopping Zerotier-One"

		kill -9 $(pidof zerotier-one)

		rmmod -w tun
		;;
	*)
		echo "Usage: $0 {start|stop}"
		exit 1
		;;
esac

exit 0
